/*
*Copyright (c) Nikhil Jain.
*Project ICARUS, communications and 
*artificial intelligence.
*/



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package javadrone.client;

//~--- non-JDK imports --------------------------------------------------------

import javadrone.Drone;

import javadrone.client.simulator.ClientGUI;

import javadrone.command.*;

import javadrone.statedata.ErrorData.ErrorState.ErrorFlag;

//~--- JDK imports ------------------------------------------------------------

import java.rmi.RemoteException;

import javax.vecmath.Vector3d;

/**
 *
 * @author Nikzzay
 */
public class DroneCommander {
    private Thread     bootStrap;
    private DroneQuery dQ;

    public DroneCommander(final Drone drone, final CommandExecutor ce, final DroneQuery dQ,
                          final boolean backgroundMode) {
        this.dQ   = dQ;
        bootStrap = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("Waiting for bootStrap");

                    Command c;

                    do {
                        c = drone.takeCommand();

                        if (c.getDescriptor().equals(CommandDescriptor.BOOTSTRAP)) {
                            c.execute(ce);

                            break;
                        }
                    } while (true);

                    System.out.println("Bootstrap finished...");

                    // consumer.start();
                } catch (InterruptedException | RemoteException | ExecutorException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public void start() {
        bootStrap.start();
    }

    public Vector3d getCoords() {
        return dQ.getCoords();
    }

    public Vector3d getAngles() {
        return dQ.getAngles();
    }

    public boolean isHovering() {
        return dQ.isHovering();
    }

    public boolean isLanding() {
        return dQ.isLanding();
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
